
const fs = require('fs');
const softwareVersion = JSON.parse(fs.readFileSync('package.json')).version;
const Os = require('os');
module.exports = class extends think.kms.admin {
  async indexAction() {
    this.meta_title = '首页';
    this.favicon = think.config('systemInfo.browser_icon');
    this.active = ['/', '/index', 'index.html'];
    let topMenu = [];
    const menu = this.adminmenu;
    for (var i = 0; i < menu.length; i++) {
      topMenu.push(menu[i]);
    }
    this.assign({
      menus: menu,
      'software_version': softwareVersion
    });
    return this.display();
  }
  
  async mainAction() {
    let res = await this.ctx.proxy({
      menu: 'localhost:post:/admin/index/menu'
    });
    console.log(this.ctx.backData.menu)
    this.active = ['/', '/index', 'index.html'];
    const mysqlv = await this.model('mysql').query('select version()');
    const node = process.versions;
    const maxPost = this.config('post_max_fields_size');
    const maxUpload = this.config('post_max_file_size');
    this.assign({
      app_version: softwareVersion,
      ThinkJS_version: think.version,
      'nodejs_v': node.node,
      'OS': Os.type(),
      'thinkjs': think.version,
      'maxPost': maxPost,
      'maxUpload': maxUpload,
      'title': '系统信息',
      'mysqlv': mysqlv[0]['version()']
    });
    return this.display();
  }

  async loginAction() {
    this.title = 'login';
    return this.display();
  }

  async menuAction() {
    return this.json(this.adminmenu)
  }

  async systemInfoAction() {
    const mysqlv = await this.model('mysql').query('select version()');
    const info = await this.model('kms/system_config').getSystem_info();
    const node = process.versions;
    const maxPost = this.config('post_max_fields_size');
    const maxUpload = this.config('post_max_file_size');
    console.log(info)
    return this.json({
      app_version: softwareVersion,
      'system_version': info.app_version,
      ThinkJS_version: think.version,
      'nodejs_v': node.node,
      'OS': Os.type(),
      'thinkjs': think.version,
      'maxPost': maxPost,
      'maxUpload': maxUpload,
      'title': '系统信息',
      'mysqlv': mysqlv[0]['version()']
    })
  }
};
